package hjslm.Controller.Background;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import hjslm.Bean.UserBean;
import hjslm.Service.IUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import framework.base.controller.BaseController;

@Controller
@RequestMapping("/b_user")
public class UserController extends BaseController{

	/**
	 * 用户控制层
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	IUserService userService;

	@Override
	public void setLogger() {
	}
	
	@RequestMapping("/index")
	public ModelAndView index(){
		ModelAndView modelAndView =new ModelAndView("background/user/index");
		return modelAndView;
	}
	
	@RequestMapping("/check")
	public void check(String password,String originpassword,HttpServletResponse response){
		int ret = 0;//原始密码错误
		if (originpassword == null || "".equals(originpassword)) {
			ret = 0;
		}
		else {
			UserBean bean;
			bean = new UserBean();
			bean.setPassword(originpassword);
			bean = userService.selectOne(bean);
			if (bean != null) {
				UserBean bean2  = new UserBean();
				bean2.setId(bean.getId());
				bean2.setPassword(password);
				if (userService.update(bean2)>0) {
					ret = 1;
				}
			}
		}
		try {
			PrintWriter out = response.getWriter();
			out.print(ret);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	

}
